﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using PBDesk.Business.Gigya;


namespace PBDesk.Business.UserManager
{
    public class LogonHelper
    {
        public static LogonStatus LogonUser(NameValueCollection qsParameters)
        {
            LogonStatus result = LogonStatus.Failure;
            
            if (qsParameters != null && qsParameters.Count > 0)
            {
                GigyaUser gUser = GigyaHelper.GetGigyaUserFromQS(qsParameters);
                if (gUser != null)
                {
                    LeisureUserAuthInfo o = CommonHelper.GetLeisureUserAuthInfo(gUser);
                    if (o != null)
                    {
                        LeisureUser lUser =  LeisureMembership.GetLeisureUser(o);
                        if (lUser == null)
                        {
                            //No record found in db. new user. user first time loging in
                            result = LogonStatus.NewUser;
                        }
                        else
                        {
                            result = LogonStatus.Success;
                        }
                    }
                    

                }
            }
            return result;
        }
    }
}
